<?php

namespace app\superadmin\controller;
use app\common\controller\SuperadminBase;
use app\superadmin\model\Report as Model;
use think\Controller;

use think\Db;

use think\Request;

use think\Session;



class Report extends SuperadminBase

{



    public function index()
    {

        $stafflist = Db::table('yup_user')->where('is_staff',1)->select();

        $this->assign('stafflist', $stafflist);
        return $this->fetch();

    }



    //获取报告列表

    public function gList(Request $request)

    {

        //获取每页显示的条数

        $limit = $request->param('limit');

        //获取当前页数

        $page = $request->param('page');

        $keywords = $request->param('keywords');

        $create_time = $request->param('create_time');

        $status = $request->param('status');

        $staffid = $request->param('staffid');

        $where = [];

        $statuswhere = [];

        

        if (!empty($status)) {
             
             $where['status'] = $status;
        }else{

            $statuswhere['status'] = ['>',0];
        }


        if (!empty($staffid)) {
             
             $where['staffid'] = $staffid;
        }



        if (!empty($create_time)) {
             
             $where['create_time'] = ['between',explode(' - ', $create_time)];
        }



        $goodList = Model::with('userinfo')->with('staffinfo')->with('orderinfo')->where($where)->where('code|brand|car_num', 'like', '%' . $keywords . '%')->where($statuswhere)->order('create_time desc')->paginate($limit, false, ['page' => $page])->toArray();

        return json(['code' => 0, 'msg' => '', 'count' => $goodList['total'], 'data' => $goodList['data']]);

    }

    
  
     public function shenhe(){

        $id       = input('id');

        $status       = input('status');

        $info = Model::where('id',$id)->find();

        $arr = [];
        $arr['status'] = $status;

        //halt($info);
        
        if ($status == 2) {
            
            Db::table('yup_order')->where('id',$info['oid'])->update(['status'=>4]);

            $arr['end_time'] = date('Y-m-d');

        }else if ($status == 3) {
            Db::table('yup_order')->where('id',$info['oid'])->update(['status'=>3]);
        }

        Model::where('id',$id)->update($arr);

        



        return 1;

    }




    public function look(){

        $id       = input('id');

        $info = Model::with('userinfo')->with('serviceinfo')->where('id',$id)->find();
       
        $this->assign('info', $info);

        return $this->fetch('order/look');

    }







}

